Skip to content

Fix GH-22666: pdo_odbc heap overflow on oversized output param#22674

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-22666-pdo-odbc-param-overflow
Open

Fix GH-22666: pdo_odbc heap overflow on oversized output param#22674
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-22666-pdo-odbc-param-overflow

Conversation

@iliaal

@iliaal iliaal commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

ext/pdo_odbc sizes an output-param buffer from the declared maxlen but copies the runtime value in by its own length (heap write overflow) and reads it back by the driver-reported length, which on a truncated OUTPUT value exceeds the buffer (01004 over-read). Records the bound capacity and clamps both the input copy and the read-back to it. Over-long values are bounded to maxlen, which is all the driver round-trips anyway since the buffer is bound at maxlen before the value is known. Reproduces with the SQLite3 ODBC driver; the test skips without it.

Fixes #22666

odbc_stmt_param_hook() sizes an output-param buffer from the declared maxlen
but then copies the runtime value into it using the value's own length, and
at fetch-back hands ZVAL_STRINGL the driver-reported length. Both trust a
length that can exceed the buffer: the input copy overflows the heap
(controlled write), and on a truncated OUTPUT value the driver reports the
full length via the shared indicator, so the readback over-reads. Record the
bound capacity in a new outbuflen field and clamp the copy and the readback to
it. LOB output is rejected at bind, so those copy sites stay unreachable.

Fixes phpGH-22666

@NattyNarwhal NattyNarwhal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, just is blocking on either being reproducible in SQL Server (and being like the other tests), or adding the SQLite ODBC driver to CI (which is blocking your other PRs) and changing to :memory:

@iliaal

iliaal commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

I added PR (tagged you on it) with sqlite odbc lib (1 liner) #22686

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants